﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class CurrencyExchangeTest
    {
        [TestMethod]
        public void GeneralCurrencyExchangeTest()
        {
            CurrencyExchange currencyExchange = new CurrencyExchange();

            Assert.AreEqual(DateTime.Today, currencyExchange.Date);
            Assert.AreEqual(100.0, currencyExchange.Price);
            Assert.IsNull(currencyExchange.From);
            Assert.IsNull(currencyExchange.To);

            Currency from = new Currency();
            Currency to = new Currency();
            currencyExchange.From = from;
            currencyExchange.To = to;

            Assert.AreEqual("", currencyExchange.Validate());
        }

        [TestMethod]
        public void CurrencyExchangeFromPropertyChangedTest()
        {
            CurrencyExchange currencyExchange = new CurrencyExchange();
            Assert.IsNull(currencyExchange.From);

            Currency from = new Currency();
            AssertHelper.PropertyChangedEvent(currencyExchange, x => x.From, () => currencyExchange.From = from);
            Assert.AreEqual(from, currencyExchange.From);
        }

        [TestMethod]
        public void BillItemPricePropertyChangedTest()
        {
            Bill bill = new Bill();
            Assert.IsNull(bill.ItemPrice);

            ItemPrice itemPrice = new ItemPrice();
            AssertHelper.PropertyChangedEvent(bill, x => x.ItemPrice, () => bill.ItemPrice = itemPrice);
            Assert.AreEqual(itemPrice, bill.ItemPrice);
        }
        
        [TestMethod]
        public void CurrencyExchangeFromValidationTest()
        {
            CurrencyExchange currencyExchange = new CurrencyExchange();

            Assert.IsNull(currencyExchange.From);
            Assert.AreEqual(Resources.ExchangeFromMandatory, currencyExchange.Validate("From"));

            Currency currency = new Currency();
            currencyExchange.From = currency;
            Assert.AreEqual("", currencyExchange.Validate("From"));
        }

        [TestMethod]
        public void CurrencyExchangeToValidationTest()
        {
            CurrencyExchange currencyExchange = new CurrencyExchange();

            Assert.IsNull(currencyExchange.To);
            Assert.AreEqual(Resources.ExchangeToMandatory, currencyExchange.Validate("To"));

            Currency currency = new Currency();
            currencyExchange.To = currency;
            Assert.AreEqual("", currencyExchange.Validate("To"));
        }

        [TestMethod]
        public void CurrencyExchangePriceValidationTest()
        {
            CurrencyExchange currencyExchange = new CurrencyExchange();

            Assert.AreEqual(100, currencyExchange.Price);

            currencyExchange.Price = 0.1;
            Assert.AreEqual("", currencyExchange.Validate("Price"));
            currencyExchange.Price = 0.0;
            Assert.AreEqual(Resources.ExchangePriceGreater, currencyExchange.Validate("Price"));
            currencyExchange.Price = -0.1;
            Assert.AreEqual(Resources.ExchangePriceGreater, currencyExchange.Validate("Price"));
        }
    }
}
